<template>
  <!-- 添加或修改应付账单对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="供应商id" prop="supplierId">
                <el-input v-model="form.supplierId" placeholder="请输入供应商id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供应商名称" prop="supplierName">
                <el-input v-model="form.supplierName" placeholder="请输入供应商名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发生日期" prop="occurDate">
                <el-date-picker clearable
                                v-model="form.occurDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择发生日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="到期日期" prop="dueDate">
                <el-date-picker clearable
                                v-model="form.dueDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择到期日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="应付金额" prop="payMoney">
                <el-input v-model="form.payMoney" placeholder="请输入应付金额"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="已付金额" prop="paidMoney">
                <el-input v-model="form.paidMoney" placeholder="请输入已付金额"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="剩余金额" prop="remainMoney">
                <el-input v-model="form.remainMoney" placeholder="请输入剩余金额"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发票id" prop="invoiceId">
                <el-input v-model="form.invoiceId" placeholder="请输入发票id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="编号" prop="invoiceNos">
                <el-input v-model="form.invoiceNos" placeholder="请输入编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发票编号" prop="invoiceCode">
                <el-input v-model="form.invoiceCode" placeholder="请输入发票编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="打款id" prop="payRecordId">
                <el-input v-model="form.payRecordId" placeholder="请输入打款id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="打款记录编号" prop="payRecordNo">
                <el-input v-model="form.payRecordNo" placeholder="请输入打款记录编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="描述" prop="desc">
                <el-input v-model="form.desc" placeholder="请输入描述"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="删除标志" prop="delFlag">
                <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "FinanceApForm",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/financeAp/financeAp/',
        add: '/financeAp/financeAp/add',
        edit: '/financeAp/financeAp/edit',
      },
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        supplierId: null,
        supplierName: null,
        occurDate: null,
        dueDate: null,
        payMoney: null,
        paidMoney: null,
        remainMoney: null,
        status: "0",
        invoiceId: null,
        invoiceNos: null,
        invoiceCode: null,
        payRecordId: null,
        payRecordNo: null,
        desc: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加应付账单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改应付账单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
